import { defineStore } from "pinia";
import { reqHospitalDetail, reqHospitalDepartment } from "@/api/hospital"
import type { HospitalDetail,HosPitalDetail,DepartmentResponseData } from "@/api/hospital/type"
import type { DetailState } from "./interface"

const useDetailStore = defineStore("counter", {
  state: ():DetailState => {
    return {  
      // 医院详情的数据
      hospitalInfo:({} as HosPitalDetail),
      departmentArr:[]
    };
  },
  actions: {
    async getHospital(hoscode:string){
      const result:HospitalDetail=await reqHospitalDetail(hoscode)
      if(result.code==200){
        this.hospitalInfo=result.data
      }
    },
    // 获取某一个医院科室的数据
    async getDepartment(hoscode:string){
      let result:DepartmentResponseData=await reqHospitalDepartment(hoscode)
      if(result.code===200){
        this.departmentArr=result.data
      }
    }
  },
  getters: {},
  persist: true,
});

export default useDetailStore;
